﻿@{ Layout = "~/Views/Shared/_ModalForm.cshtml";
    AddEditUserDto dto = ViewBag.User;
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <input id="id" col="Id" type="text" class="hidden" />
        <div class="form-group">
            <label class="col-sm-2 control-label ">账号</label>
            <div class="col-sm-4">
                <input id="account" col="Account" type="text" readonly="readonly" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">姓名<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="name" col="Name" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">

            <label class="col-sm-2 control-label ">性别</label>
            <div class="col-sm-4" id="gender" col="Gender"></div>
            <label class="col-sm-2 control-label ">生日</label>
            <div class="col-sm-4">
                <input id="birthday" col="Birthday" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">邮箱</label>
            <div class="col-sm-4">
                <input id="email" col="Email" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">手机</label>
            <div class="col-sm-4">
                <input id="mobile" col="Mobile" type="text" class="form-control" />
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">微信</label>
            <div class="col-sm-4">
                <input id="weChat" col="WeChat" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">QQ</label>
            <div class="col-sm-4">
                <input id="qq" col="Qq" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">描述</label>
            <div class="col-sm-10">
                <textarea id="description" col="Description" class="form-control" style="height:90px"></textarea>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    $(function () {
        $("#gender").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(GenderType).EnumToDictionaryJson())) });
        $('#account').attr('disabled', 'true');
        laydate.render({ elem: '#birthday', format: 'yyyy-MM-dd',trigger:'click' });
        
        getForm();

        $("#form").validate({
            rules: {
                account: { required: true, maxlength: 15},
                name: { required: true, maxlength: 31},
                mobile: { isPhone: true, maxlength: 15},
                email: { email: true, maxlength: 63 },
                //qq: { email: true, maxlength: 16 },
                wechat: {maxlength: 31 },
            }
        });
    });

    function getForm() {
        var defaultData = {};
        defaultData.Id ='@dto.Id';
        defaultData.Account ='@dto.Account';
        defaultData.Name = '@dto.Name';
        defaultData.Gender ='@dto.Gender';
        defaultData.Birthday = '@dto.Birthday';
        defaultData.Email ='@dto.Email';
        defaultData.Mobile = '@dto.Mobile';
        defaultData.WeChat = '@dto.WeChat';
        defaultData.Qq = '@dto.Qq';
        defaultData.Description = '@dto.Description';
        $("#form").setWebControls(defaultData);

    }

    function saveForm(index) {
        if (!ys.checkTextLenth("description", "描述", 0, 127)) return;

        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls({ Id: id });

            ys.ajax({
                url: '@Url.Content("~/Sys/User/")' + 'UpdateSelf',
                type: "post",
                data: postData,
                success: function (rst) {
                    if (rst.Flag == 1) {
                        ys.msgSuccess(rst.Message);
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(rst.Message);
                    }
                }
            });
        }
    }
</script>
